import java.util.Scanner;
import java.util.Random;

public class GuessNumberGame {
    public static void main(String[] args) {
        // 生成随机数字
        Random random = new Random();
        int numberToGuess = random.nextInt(100) + 1;
        int numberOfTries = 0;
        Scanner input = new Scanner(System.in);

        // 开始游戏循环
        while (true) {
            System.out.print("请猜一个1到100之间的数字：");
            int guess = input.nextInt();
            numberOfTries++;

            // 检查猜测是否正确
            if (guess == numberToGuess) {
                System.out.println("恭喜你，你猜对了！用了" + numberOfTries + "次尝试。");
                break;
            } else if (guess < numberToGuess) {
                System.out.println("你猜小了。再试一次！");
            } else if (guess > numberToGuess) {
                System.out.println("你猜大了。再试一次！");
            }
        }
        input.close();
    }
}